package com.dragon.client.controller.contract;

import com.dragon.common.model.Insert;
import com.dragon.common.model.ResponseData;
import com.dragon.common.model.Update;
import com.dragon.logical.service.contract.IOtherFileService;
import com.dragon.repository.domain.dto.OtherFileDTO;
import com.dragon.repository.domain.vo.OtherFileVO;
import com.dragon.repository.entity.OtherFile;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sy
 * @since 2023-07-06
 */
@RestController
@RequestMapping("otherFile")
@Api(tags = "附件")
public class OtherFileController {

    @Autowired
    IOtherFileService service;

    @PostMapping("add")
    @ApiOperation("添加附件")
    public ResponseData addFile(@RequestBody @Validated(Insert.class) OtherFileVO vo){
        service.addFile(OtherFileVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("update")
    @ApiOperation("更新附件")
    public ResponseData updateFile(@RequestBody @Validated(Update.class) OtherFileVO vo ){
        service.updateFile(OtherFileVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("delete")
    @ApiOperation("删除附件")
    public ResponseData deleteFile( @RequestParam
                                        @ApiParam(name = "id", value = "附件ID", required = true,type = "int") Integer id){
        service.deleteFile(id);
        return ResponseData.success();
    }

    @GetMapping("list")
    @ApiOperation("查看附件列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "correlationId", value = "关联主表id", required = true,  type = "int"),
            @ApiImplicitParam(name = "streamType", value = "流程类型", required = true, type = "int")
    })
    public ResponseData<List<OtherFileDTO>> fileList(@RequestParam Integer correlationId, @RequestParam Integer streamType){
        List<OtherFile> list = service.fileList(correlationId,streamType);
        return ResponseData.success(OtherFileDTO.convertList(list));
    }

}
